
/******************************************************************************
 *  A Teaching GA					  Developed by Hal Stringer & Annie Wu, UCF
 *  Version 2, January 18, 2004
 *******************************************************************************/
import java.io.*;
import java.util.*;
import java.text.*;

public class Parameters {

   /*******************************************************************************
    *                            INSTANCE VARIABLES                                *
    *******************************************************************************/
   public static String expID;
   public static String problemType;
   public static String dataInputFileName;
   public static int numRuns;
   public static int generations;
   public static int popSize;
   public static int genCap;
   public static int fitCap;
   public static String minORmax;
   public static int selectType;
   public static int elitismType;
   public static int scaleType;
   public static int xoverType;
   public static double xoverRate;
   public static int mutationType;
   public static double mutationRate;
   public static long seed;
   public static int numGenes;
   public static int geneSize;
   public static int encodingType;
   public static final int BINARY_ENCODING = 1;
   public static final int GRAY_ENCODING = 2;
   // Flag is used to execute MAC OS specific commands such as file creation
   // and executing command line programs.
   public static boolean isMacOS;
   public static double sumoVersion;
   public static int sumoBeginTime;
   public static int sumoEndTime;
   public static int meanLaneDataSampleTimeSeconds;
   public static String sumoBinPath;
   public static String sumoNetworkRoutePath;
   public static String sumoOutputPath;

   public static String sumoNetworkFile;
   public static String sumoRouteFile;
   public static String sumoAdditionalParamFile;
   public static String sumoOutputFile;
   public static String sumoLaneStatisticsOutputFile;
   public static String sumoOutputRootXMLTag;

   public static int    outputSumoStatsInFile;


   /*******************************************************************************
    *                              CONSTRUCTORS                                    *
    *******************************************************************************/
   public Parameters(String parmfilename) throws java.io.IOException {

      String readLine;
      BufferedReader parmInput = new BufferedReader(new FileReader(parmfilename));

      //Detect OS to run on MAC OSX
      String osName = System.getProperty("os.name").toLowerCase();
      isMacOS = osName.startsWith("mac os x");

      expID = parmInput.readLine().substring(30);
      problemType = parmInput.readLine().substring(30);

      dataInputFileName = parmInput.readLine().substring(30);

      numRuns = Integer.parseInt(parmInput.readLine().substring(30).trim());
      generations = Integer.parseInt(parmInput.readLine().substring(30).trim());
      popSize = Integer.parseInt(parmInput.readLine().substring(30).trim());

      selectType = Integer.parseInt(parmInput.readLine().substring(30).trim());
      scaleType = Integer.parseInt(parmInput.readLine().substring(30).trim());

      xoverType = Integer.parseInt(parmInput.readLine().substring(30).trim());
      xoverRate = Double.parseDouble(parmInput.readLine().substring(30).trim());
      mutationType = Integer.parseInt(parmInput.readLine().substring(30).trim());
      mutationRate = Double.parseDouble(parmInput.readLine().substring(30).trim());

      seed = Long.parseLong(parmInput.readLine().substring(30).trim());
      numGenes = Integer.parseInt(parmInput.readLine().substring(30).trim());
      geneSize = Integer.parseInt(parmInput.readLine().substring(30).trim());

      encodingType = Integer.parseInt(parmInput.readLine().substring(30).trim());
      elitismType = Integer.parseInt(parmInput.readLine().substring(30).trim());

      /// SUMO Parameters
      sumoVersion   = Double.parseDouble(parmInput.readLine().substring(30).trim());
      sumoBeginTime = Integer.parseInt(parmInput.readLine().substring(30).trim());
      sumoEndTime   = Integer.parseInt(parmInput.readLine().substring(30).trim());
      meanLaneDataSampleTimeSeconds = Integer.parseInt(parmInput.readLine().substring(30).trim());
      
      sumoBinPath                  = parmInput.readLine().substring(30).trim();
      sumoNetworkRoutePath         = parmInput.readLine().substring(30).trim();
      sumoOutputPath               = parmInput.readLine().substring(30).trim();

      sumoNetworkFile              = parmInput.readLine().substring(30).trim();
      sumoRouteFile                = parmInput.readLine().substring(30).trim();
      sumoAdditionalParamFile      = parmInput.readLine().substring(30).trim();
      sumoOutputFile               = parmInput.readLine().substring(30).trim();
      sumoLaneStatisticsOutputFile = parmInput.readLine().substring(30).trim();
      sumoOutputRootXMLTag         = parmInput.readLine().substring(30).trim();

      outputSumoStatsInFile = Integer.parseInt(parmInput.readLine().substring(30).trim());


      parmInput.close();

      if (scaleType == 0 || scaleType == 2) {
         minORmax = "max";
      } else {
         minORmax = "min";
      }

   }

   /*******************************************************************************
    *                                MEMBER METHODS                                *
    *******************************************************************************/
   /*******************************************************************************
    *                             STATIC METHODS                                   *
    *******************************************************************************/
   public static void outputParameters(FileWriter output) throws java.io.IOException {
      output.write("Experiment ID,,," + expID + "\n");
      output.write("Problem Type,,," + problemType + "\n");

      output.write("Data Input File Name,,," + dataInputFileName + "\n");

      output.write("Number of Runs,,," + numRuns + "\n");
      output.write("Generations per Run,,," + generations + "\n");
      output.write("Population Size,,," + popSize + "\n");

      output.write("Selection Method,,," + selectType + "\n");
      output.write("Fitness Scaling Type,,," + scaleType + "\n");
      output.write("Min or Max Fitness,,," + minORmax + "\n");

      output.write("Crossover Type,,," + xoverType + "\n");
      output.write("Crossover Rate,,," + xoverRate + "\n");
      output.write("Mutation Type,,," + mutationType + "\n");
      output.write("Mutation Rate,,," + mutationRate + "\n");

      output.write("Random Number Seed,,," + seed + "\n");
      output.write("Number of Genes/Points,,," + numGenes + "\n");
      output.write("Size of Genes,,," + geneSize + "\n");
      output.write("Encoding Type,,," + encodingType + "\n");
      output.write("Elitism Type,,," + elitismType + "\n");

      output.write("SUMO Version,,," + sumoVersion + "\n");
      output.write("SUMO Begin Time,,," + sumoBeginTime + "\n");
      output.write("SUMO End Time,,," + sumoEndTime + "\n");
      output.write("SUMO LaneData Sample Time,,," + meanLaneDataSampleTimeSeconds + "\n");

      output.write("\n\n");

   }
}   // End of Parameters.java **************************************************

